package com.dynamic.model.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.dynamic.model.common.dao.BaseDao;
import com.dynamic.model.common.vo.Page;
import com.dynamic.model.dao.SystemUserDao;
import com.dynamic.model.model.po.SysmanUser;
import com.dynamic.model.service.SystemUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import com.dynamic.model.common.service.impl.BaseServiceImpl;

/**
 * 
 * @desc 用户后台登陆用户表--RBAC权限管理service接口实现类
 *
 * @author luwei
 * @Fri Aug 08 14:25:29 CST 2014
 */
@Service
public class SystemUserServiceImpl extends BaseServiceImpl<SysmanUser> implements SystemUserService {

	@Override
	@Resource(name ="systemUserDaoImpl")
	public void setBaseDao(BaseDao<SysmanUser> dao) {
		this.baseDao =  dao;
	}
	
	private SystemUserDao getDao(){
		return (SystemUserDao) this.baseDao ;
	}

	@Override
	public SysmanUser findByName(String userName) {
		return this.getDao().findByName(userName);
	}

	@Override
	public List<SysmanUser> getPageDataByName(Page<SysmanUser> page, String username, String realname, String statu) {
		Subject subject = SecurityUtils.getSubject();
		SysmanUser user = (SysmanUser) subject.getPrincipal();
		return this.getDao().getPageDataReqName(page,username,realname,statu,user.getPid(),user.getUserType());
	}
	
	
	@Override
	public void save(SysmanUser entity) throws Exception {
		Subject subject = SecurityUtils.getSubject();
		SysmanUser user = (SysmanUser) subject.getPrincipal();
		entity.setCreater(user.getPid());
		entity.setUserType(user.getUserType());
		this.getBaseDao().save(entity);
	}

	@Override
	public void update(SysmanUser entity) throws Exception {
		Subject subject = SecurityUtils.getSubject();
		SysmanUser user = (SysmanUser) subject.getPrincipal();
		entity.setCreater(user.getPid());
		entity.setUserType(user.getUserType());
		this.getBaseDao().update(entity);
	}
}
